package fons.model.ontology.language;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

public class Vocabulary {
	private final Map<String, List<Named>> multimap = Maps.newHashMap();

	public void add (Named named) {
		Set<String> words = Sets.newHashSet(named.getSynonymes());
		words.add(named.getName());
		
		for (String Word: words) {
			final String word = Word.toLowerCase();
			
			if (word.equals("")) continue;
			
			if (multimap.containsKey(word)) {
				multimap.get(word).add(named);
			} else {
				multimap.put(word, Lists.newArrayList(named));
			}
		}
	}
		
	public void add (Named... nameds) {
		for (Named element: nameds) {
			this.add(element);
		}
	}
	
	public void add (Collection<? extends Named> nameds) {
		for (Named element: nameds) {
			this.add(element);
		}
	}

	public Collection<String> getWords() {
		return multimap.keySet();
	}
	
	public Collection<Named> getMeanings(String word) {
		return multimap.get(word);
	}
}
